<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back_white.png"></image
      ></view>
      <!-- <view class="jtop_l" @tap="navigateBack">关闭</view> -->
      <view class="jtop_c">
        <view> {{ nian }}年{{ yue }}月 </view>
      </view>
      <view class="jtop_r" @tap="to_add">月报</view>
    </view>

    <view class="tophr"></view>
    <view class="content">
      <ren-calendar
        ref="ren"
        :markDays="markDays"
        :open="true"
        :disabledAfter="true"
        @onDayClick="onDayClick"
      ></ren-calendar>
      <!-- <view class="change">选中日期：{{curDate}}</view> -->
    </view>

    <view class="cf">
      <view class="cf_b">
        <view class="cf01">
          上下班打卡
        </view>
        <view class="cf02">
          打卡规则：上班08:00，下班18:00 | 工作时长：8小时
        </view>
      </view>
    </view>

    <!-- 无内容 -->
    <view class="no" v-if="!nodata">
      <view class="no_t">
        <image src="../../static/img/index/2/ic_no data_grey.png"></image>
      </view>
      <view class="no_c">
        暂无数据
      </view>
    </view>

    <view class="" v-if="nodata">
      <view class="cf" v-for="(item, index) in items" :key="index">
        <view class="cf_b">
          <view class="cf03"> 08:00{{ item.name }} </view>
          <view class="cf04">
            <view class="cf04t">
              上班
            </view>
            <view class="cf04f">
              正常打卡
            </view>
          </view>
        </view>
      </view>

      <view class="cf">
        <view class="cf_b">
          <view class="cf03">
            08:00
          </view>
          <view class="cf04">
            <view class="cf04t">
              上班
            </view>
            <view class="cf04f">
              正常打卡
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import RenCalendar from '@/components/ren-calendar/ren-calendar.vue';
export default {
  components: {
    RenCalendar,
  },
  data() {
    return {
      repeat_click: true,
      curDate: '',
      markDays: [],
      collapsible: false,

      nian: '',
      yue: '',

      nodata: false,
      items: '',
      jqeditid: '',
      ashowpop2: false,
      projectId: uni.getStorageSync('dqfull_name').id,
      today: '',
      week: '',
      jimg: '',
      zong: '0',
    };
  },

  onShow() {
    // let today = this.$refs.ren.getToday().date;
    this.nian = new Date().getFullYear();
    this.yue = new Date().getMonth() + 1;

    var date = new Date();
    var Y = date.getFullYear();
    var M =
      date.getMonth() + 1 < 10
        ? '0' + (date.getMonth() + 1)
        : date.getMonth() + 1;
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();

    var now = new Date();
    var day = now.getDay();
    var weeks = new Array(
      '星期日',
      '星期一',
      '星期二',
      '星期三',
      '星期四',
      '星期五',
      '星期六',
    );
    var week = weeks[day];

    this.week = week;

    let today = Y + '-' + M + '-' + D;
    this.jt = Y + '年' + M + '月' + D + '日';
    this.today = today;
    console.log('ddddd:', today);
    this.curDate = today;
    this.markDays.push(today);
    this.lb(this.curDate);
  },

  onReady() {
    let today = this.$refs.ren.getToday().date;
    this.curDate = today;
    this.markDays.push(today);
  },
  methods: {
    lb(e) {
      // var anian = new Date().getFullYear();
      // var ayue = new Date().getMonth() + 1;
      // var ayue = new Date().getDay();
      // var rq = anian+"-"+ayue+"-"+ayue
      console.log('lbbb:', e);
      var cc = e.slice(0, 7);

      // 获取列表信息
      request({
        url: `/modor/v1/project/${this.projectId}/work/type/2/payment/statistics`,
        method: 'GET',
        data: {
          time: e,
        },

        success: res => {
          console.log('项目列表', res);
          console.log(res.data.data.length);
          if (res.data.success == true) {
            console.log('1111:', res.data.data.length);
            if (res.data.data.length > 0) {
              this.items = res.data.data;
              console.log(this.items);
              var cc = 0;
              for (var i = 0; i < res.data.data.length; i++) {
                cc = cc + res.data.data[i]['payedAmount'];
              }
              this.zong = cc;
              this.nodata = true;
            } else {
              this.items = '';
              this.nodata = false;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    // 跳转
    to_add() {
      uni.setStorageSync('nian', this.nian);
      uni.setStorageSync('yue', this.yue);
      uni.navigateTo({
        url: '../main/clock_work_m',
      });
    },

    navigateBack() {
      uni.navigateBack();
    },
    onDayClick(data) {
      this.curDate = data.date;
    },
  },
};
</script>

<style>
.cf {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
.cf_b {
  width: 690rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 30rpx;
}
.cf01 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 20rpx 0;
}
.cf02 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 0 0 20rpx;
}
.cf03 {
  width: 100rpx;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 34rpx;
  line-height: 32rpx;
  margin: 40rpx 40rpx 40rpx 0;
}
.cf04 {
  width: 500rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0rpx;
}
.cf04t {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 28rpx;
  line-height: 36rpx;
  margin: 20rpx 0 10rpx;
}
.cf04f {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 0rpx 0 22rpx;
}

.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}
.index {
  background: #ffffff;
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #256aff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 120rpx;
  color: #ffffff;
  text-align: right;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 40rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #ffffff;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_c1 {
  display: inline-block;
  margin: 0 20rpx;
  color: #ffffff;
}
.jtop_c1.active {
  color: #ffffff;
}

.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 150rpx 0 0;
}
.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}
.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}
.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}
.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}
.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

.change {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  margin-top: 100rpx;
  height: 100rpx;
  color: #b89249;
  background-color: #21191b;
}
</style>
